package com.itheima.text7;

import java.util.concurrent.Semaphore;

public class MyRunnable implements Runnable{
    //获得管理员对象
    private Semaphore semaphore =new Semaphore(2);
    @Override
    public void run() {
        try {
            //获得通行证.acquire()
            semaphore.acquire();
            System.out.println("获得了通行证开始行使");
            Thread.sleep(1000);
            System.out.println("归还通行证");
            //归还通行证
            semaphore.release();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
